home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club (Business) 1997 July / Software of the Month Club - Business (Volume 239) (July 1997).iso / pc / code / g.dxr / 00013_GFunctionAnimator.ls < prev    next >
Encoding:
Text File  |  1996-02-15  |  4.1 KB  |  127 lines

  1. property ancestor, pPathFunctionData, pCurrentLoc, pStartLoc
  2. global gCPU
  3.  
  4. on birth me, arguments
  5.   set the ancestor of me to birth(script "Animator", arguments)
  6.   set the pPathFunctionData of me to the pathData of arguments
  7.   set pStartLoc to the location of arguments
  8.   set pCurrentLoc to pStartLoc
  9.   return me
  10. end
  11.  
  12. on moveSprite me
  13.   set theResult to chaoticStockLoc(me)
  14.   set the pCurrentLoc of me to theResult
  15.   set the loc of sprite the pChannel of me to the pCurrentLoc of me
  16.   DrawXLine(me)
  17. end
  18.  
  19. on chaoticStockLoc me
  20.   set PresentOBJAnim to getaProp(getaProp(gObjects, #PresentTrendBar), #animator)
  21.   set trendOffsetH to getaProp(getaProp(gObjects, #PresentTrendBar), #trendOffsetH)
  22.   set timePricePlotList to getaProp(getaProp(gObjects, #ShortTermStock), #timePricePlotPoints)
  23.   set lastY to getaProp(getaProp(gObjects, #ShortTermStock), #chaosLastY)
  24.   set PresentLoc to the pCurrentLoc of PresentOBJAnim
  25.   set V to the locV of PresentLoc
  26.   if V < 0 then
  27.     return point(-1000, -1000)
  28.   end if
  29.   set timeInterval to getaProp(getaProp(gObjects, #ShortTermStock), #timeInterval)
  30.   set left to 34
  31.   set height to 39.0
  32.   set bottom to 79
  33.   set top to 40
  34.   set width to 526
  35.   set m to 1
  36.   set stockRef to getaProp(getaProp(gObjects, #ShortStocks), #currentChildDown)
  37.   set chaosGenAList to getaProp(getaProp(gObjects, #ShortTermStock), #chaosGenA)
  38.   set a to getaProp(chaosGenAList, stockRef)
  39.   set trendH to the locH of PresentLoc - trendOffsetH
  40.   if trendH > 526 then
  41.     set trendH to 34 + trendH - 526
  42.   else
  43.     if trendH < 34 then
  44.       set trendH to 526 - (34 - trendH)
  45.     end if
  46.   end if
  47.   if lastY = #NULL then
  48.     set chaosSeedYList to getaProp(getaProp(gObjects, #ShortTermStock), #chaosSeedY)
  49.     set yn to getaProp(chaosSeedYList, stockRef)
  50.   else
  51.     set yn to lastY
  52.   end if
  53.   repeat with i = 1 to integer(timeInterval / 2)
  54.     set yn to a * yn * (1 - yn)
  55.   end repeat
  56.   setaProp(getaProp(gObjects, #ShortTermStock), #chaosLastY, yn)
  57.   set trendV to top + ((1 - yn) * height)
  58.   set trendLoc to point(trendH, trendV)
  59.   updateTimePricePlotPoints(trendLoc)
  60.   return trendLoc
  61. end
  62.  
  63. on ranStockloc me
  64.   set startloc to the pCurrentLoc of me
  65.   set V to the locV of startloc
  66.   if V < 0 then
  67.     return point(-1000, -1000)
  68.   end if
  69.   set H to the locH of startloc + 2
  70.   if H > 526 then
  71.     set H to 34
  72.   end if
  73.   if random(2) = 1 then
  74.     set V to V + random(10)
  75.     if V > 79 then
  76.       set V to 79 - random(10)
  77.     end if
  78.   else
  79.     set V to V - random(10)
  80.     if V < 40 then
  81.       set V to 40 + random(10)
  82.     end if
  83.   end if
  84.   set aloc to point(H, V)
  85.   updateTimePricePlotPoints(aloc)
  86.   return aloc
  87. end
  88.  
  89. on DrawXLine
  90.   set xLineXOBJ to getaProp(getaProp(gObjects, #TrendPlotter), #LineXOBj)
  91.   set previousPoint to getaProp(getaProp(gObjects, #ShortTermStock), #pricePricePreviousPoint)
  92.   set newPoint to pricePriceLoc()
  93.   if objectp(xLineXOBJ) then
  94.     if gCPU = #mac then
  95.       set colorIndex to getIndex([8: 226, 16: 995, 32: 65305])
  96.       xLineXOBJ(mDrawLine, previousPoint, newPoint, 1, colorIndex)
  97.     else
  98.       if gCPU = #mpc then
  99.         xLineXOBJ(mDrawLine, "stage", previousPoint, newPoint, 1, 29)
  100.       end if
  101.     end if
  102.   end if
  103.   setaProp(getaProp(gObjects, #ShortTermStock), #pricePricePreviousPoint, newPoint)
  104. end
  105.  
  106. on pricePriceLoc
  107.   set dataList to getaProp(getaProp(gObjects, #ShortTermStock), #timePricePlotPoints)
  108.   set timeInterval to getaProp(getaProp(gObjects, #ShortTermStock), #timeInterval)
  109.   set locOffset to getaProp(getaProp(gObjects, #ShortTermStock), #pricePriceOriginLoc)
  110.   set pricePriceXScaleFactor to getaProp(getaProp(gObjects, #ShortTermStock), #pricePriceXScaleFactor)
  111.   set pricePriceYScaleFactor to getaProp(getaProp(gObjects, #ShortTermStock), #pricePriceYScaleFactor)
  112.   if count(dataList) > 0 then
  113.     set newPresentCoordinate to getAt(dataList, count(dataList)) * pricePriceXScaleFactor
  114.   else
  115.     set newLoc to point(0, 0) + locOffset
  116.     return newLoc
  117.   end if
  118.   if count(dataList) > timeInterval then
  119.     set newPastCoordinate to getAt(dataList, count(dataList) - (timeInterval - 1)) * pricePriceYScaleFactor * -1
  120.   else
  121.     set newLoc to point(0, 0) + locOffset
  122.     return newLoc
  123.   end if
  124.   set newLoc to point(newPresentCoordinate, newPastCoordinate) + locOffset
  125.   return newLoc
  126. end
  127.